<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="UTF-8">
  <title>{{ meta.title }}</title>
  <meta name="referrer" content="no-referrer">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/video.js@7.6.6/dist/video-js.min.css">
  <style type="text/css">
    * {
  		margin: 0;
  		padding: 0;
  	}
  	html, body {
  		height: 100%;
  		overflow: hidden;
  	}

  	body {
  		text-align: center;
  		background: black;
  	}

    h1 {
      padding: 30px;
      color: #bdbdbd;
      font-size: 45px;
      font-weight: normal;
      box-sizing: border-box;
    }

    video:focus {
      outline: none;
    }

    .wrapper {
      width: 100%;
      margin: auto;
      height: 100%;
      text-align: center;
    }

    .video-js {
      width: 100% !important;
      height: 100% !important;
      position: relative !important;
    }

    .vjs-big-play-button {
      margin-top: -130px !important;
    }

    @media (max-width: 1200px) {
      body{
        background: #1d1d1d;
      }

      h1 {
        padding: 0.75rem;
        color: #bdbdbd;
        font-size: 1.1252rem;
        font-weight: normal;
        box-sizing: border-box;
      }
    }
  </style>
</head>
<body>

<h1>{{ meta.title }}</h1>

<div class="wrapper">
	<video id=player width=960 height=540 class="video-js vjs-default-skin vjs-big-play-centered" controls>
	  <source src="data:application/vnd.apple.mpegurl;base64,{{meta.code}}" type="application/vnd.apple.mpegurl">
	</video>
</div>

<script>
var params;
try {
  params = JSON.parse('{{ meta.params | safe }}');
} catch (e) {
  params = {}
}

(function() {
  var open = XMLHttpRequest.prototype.open;

  XMLHttpRequest.prototype.open = function (method, url, async, user, password) {
    if (!async || /^data:/.test(this.url) || /\.(key|m3u8)$/.test(this.url)) {
      return open.apply(this, arguments);
    }

    var oldReady = this.onreadystatechange;
    this.onreadystatechange = function () {
      if (this.readyState == 4) {
        var resp = this.response;
        Object.defineProperty(this, 'response', {
          get: function () {
            return resp.slice(params.padding);
          }
        });
      }

      return oldReady.apply(this, arguments);
    }

    return open.apply(this, arguments);
  }
})();
</script>

<script src="https://cdn.jsdelivr.net/npm/video.js@7.6.6/dist/video.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/videojs-hotkeys@0.2.25/videojs.hotkeys.min.js"></script>
<script>
var player = videojs('player', {
  html5: {
    hls: {
      overrideNative: params.padding > 0 || !videojs.browser.IS_SAFARI,
    }
  },
  playbackRates: [0.5, 1, 1.5, 2]
});

videojs.Hls.xhr.beforeRequest = function(options) {
  if (options.headers) {
      delete options.headers.Range
  }

  return options;
}

player.ready(function () {
  this.hotkeys({
    seekStep: 5,
    volumeStep: 0.1,
    enableModifiersForNumbers: false
  });
});

player.on('play', function () {
  document.querySelector('h1').style.display = 'none';
});
</script>

</body>
</html>
